import type { Column } from "@/components/CrudPage/type";
import { IconSelect } from "@/components/ReIcon";
import { ref } from "vue";

import {
  deleteAssetFile,
  type AssetFile
} from "@/views/domain/assets/api/assetsFile";
import { messager } from "@/utils/message";

export function useAssetFileProvider() {
  // 列配置
  const columns: Column[] = [
    {
      label: "文件id",
      prop: "id",
      slot: "id",
      hide: true,
      search: false,
      create: false,
      edit: false,
      colProps: { span: 12 }
      // cellRenderer: ({ row }) => (<div />) // render in table
      // renderField: (value, onChange) => (<div/>) // render in form
    },
    {
      label: "文件名称",
      prop: "name",
      slot: "name",
      search: false,
      create: false,
      edit: false,
      colProps: { span: 12 }
      // cellRenderer: ({ row }) => (<div />) // render in table
      // renderField: (value, onChange) => (<div/>) // render in form
    },
    {
      label: "文件格式",
      prop: "ext",
      slot: "ext",
      hide: true,
      search: false,
      create: false,
      edit: false,
      colProps: { span: 12 }
      // cellRenderer: ({ row }) => (<div />) // render in table
      // renderField: (value, onChange) => (<div/>) // render in form
    },
    {
      label: "文件哈希码",
      prop: "hash",
      slot: "hash",
      search: false,
      create: false,
      edit: false,
      hide: true,
      colProps: { span: 12 }
      // cellRenderer: ({ row }) => (<div />) // render in table
      // renderField: (value, onChange) => (<div/>) // render in form
    },
    {
      label: "文件大小(KB)",
      prop: "size",
      slot: "size",
      search: false,
      create: false,
      edit: false,
      colProps: { span: 12 }
      // cellRenderer: ({ row }) => (<div />) // render in table
      // renderField: (value, onChange) => (<div/>) // render in form
    },
    {
      label: "文件路径",
      prop: "path",
      slot: "path",
      search: false,
      create: false,
      edit: false,
      colProps: { span: 12 }
      // cellRenderer: ({ row }) => (<div />) // render in table
      // renderField: (value, onChange) => (<div/>) // render in form
    },
    {
      label: "文件夹ID",
      prop: "dirId",
      slot: "dirId",
      search: false,
      create: false,
      edit: false,
      hide: true,
      colProps: { span: 12 }
      // cellRenderer: ({ row }) => (<div />) // render in table
      // renderField: (value, onChange) => (<div/>) // render in form
    },
    {
      label: "文件修改时间",
      prop: "modTime",
      slot: "modTime",
      search: false,
      create: false,
      edit: false,
      colProps: { span: 12 }
      // cellRenderer: ({ row }) => (<div />) // render in table
      // renderField: (value, onChange) => (<div/>) // render in form
    },
    {
      label: "文件类型(自定义枚举)",
      prop: "fileType",
      slot: "fileType",
      search: false,
      create: false,
      edit: false,
      hide: true,
      colProps: { span: 12 }
      // cellRenderer: ({ row }) => (<div />) // render in table
      // renderField: (value, onChange) => (<div/>) // render in form
    },
    {
      label: "媒体(图片/视频)宽",
      prop: "width",
      slot: "width",
      search: false,
      create: false,
      edit: false,
      hide: true,
      colProps: { span: 12 }
      // cellRenderer: ({ row }) => (<div />) // render in table
      // renderField: (value, onChange) => (<div/>) // render in form
    },
    {
      label: "媒体(图片/视频)高",
      prop: "height",
      slot: "height",
      search: false,
      create: false,
      edit: false,
      hide: true,
      colProps: { span: 12 }
      // cellRenderer: ({ row }) => (<div />) // render in table
      // renderField: (value, onChange) => (<div/>) // render in form
    },
    {
      label: "操作",
      prop: "operation",
      slot: "operation"
    }
  ];

  // 删除row
  const deleteRow = (row: AssetFile) => {
    deleteAssetFile(row).then(({ ok, msg }) => {
      messager.alert(ok, msg);
    });
  };

  return {
    columns,
    deleteRow
  };
}
